package sk.tuke.lara.masplc.utils;

import java.util.Map;

import org.jacop.constraints.Constraint;
import org.jacop.constraints.XeqY;
import org.jacop.constraints.XgtC;
import org.jacop.constraints.XgteqC;
import org.jacop.constraints.XltC;
import org.jacop.constraints.XlteqC;
import org.jacop.core.IntVar;

import sk.tuke.lara.masplc.agents.ConstraintsDTO;

public class ConstraintProcessor {
    private Map<String, IntVar> varMap;

    public ConstraintProcessor(Map<String, IntVar> variablesMap) {
        varMap = variablesMap;
    }

    public Constraint processConstraint(ConstraintsDTO constraint) {
        Constraint c = null;
        switch (constraint.getOperation()) {
        case XeqY:
            c = new XeqY(varMap.get(constraint.getLeftOperator()),
                    varMap.get(constraint.getRightOperator()));
            break;
        case XgtC:
            c = new XgtC(varMap.get(constraint.getLeftOperator()),
                    Integer.parseInt(constraint.getRightOperator()));
            break;
        case XgteqC:
            c = new XgteqC(varMap.get(constraint.getLeftOperator()),
                    Integer.parseInt(constraint.getRightOperator()));
            break;
        case XltC:
            c = new XltC(varMap.get(constraint.getLeftOperator()),
                    Integer.parseInt(constraint.getRightOperator()));
            break;
        case XlteqC:
            c = new XlteqC(varMap.get(constraint.getLeftOperator()),
                    Integer.parseInt(constraint.getRightOperator()));
            break;
        default:
            System.err.println("This operation is not defined");
            break;
        }
        return c;
    }
}
